home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
misc
/
emu
/
ATUtilities.lha
/
ATUtilities
/
FTasten.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-09-26
|
18KB
|
715 lines
/* ******************************************************************* */
/* ** ** */
/* ** ATKeyboard Version 4.0 ** */
/* ** Copright (C) 1992-1994 by Thomas Dreibholz ** */
/* ** All rights reserved ** */
/* ** ** */
/* ** F-Tasten-Verwaltung ** */
/* ** ** */
/* ******************************************************************* */
#include "ATKeyboard.h"
EXTERN UBYTE *HelpName;
EXTERN LONG KickstartVersion;
extern struct Einstellungen Einstellungen;
extern struct KeyCodes *KeyCodes;
extern struct FileRequester *FileRequester;
extern struct IntuiText Trennlinie_Text;
extern struct IntuiText Wirklich_Text;
extern struct TextAttr OpalFontDef;
VOID AddKGadget();
struct IntuiText FTHilfe_Text=
{
AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
"Hilfe zum F-Tasten-Editor",
};
struct IntuiText FK_Text=
{
AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
"Kommentar ändern",
};
struct IntuiText FU_Text=
{
AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
"Rücknahme aller Aktionen",
};
struct IntuiText FL_Text=
{
AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
"FKey-Datei laden",
};
struct IntuiText FS_Text=
{
AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
"FKey-Datei sichern",
};
struct IntuiText FE_Text=
{
AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,1,&OpalFontDef,
"Übernehmen und Beenden",
};
struct MenuItem FE_Item=
{
NULL,
5,30,300,10,
HIGHIMAGE|ITEMENABLED|ITEMTEXT|COMMSEQ,
0L,
&FE_Text,
&Wirklich_Text,
'Q',NULL
};
struct MenuItem Trennlinie01_Item=
{
&FE_Item,
5,20,300,10,
HIGHNONE|ITEMTEXT,
0L,
&Trennlinie_Text,
NULL,
0,NULL
};
struct MenuItem FS_Item=
{
&Trennlinie01_Item,
5,10,300,10,
HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
0L,
&FS_Text,
NULL,
'S',NULL
};
struct MenuItem FL_Item=
{
&FS_Item,
5,0,300,10,
HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
0L,
&FL_Text,
NULL,
'L',NULL
};
struct MenuItem FK_Item=
{
NULL,
5,10,300,10,
HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
0L,
&FK_Text,
NULL,
'K',NULL
};
struct MenuItem FU_Item=
{
&FK_Item,
5,0,300,10,
HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
0L,
&FU_Text,
NULL,
'X',NULL
};
struct MenuItem FTHilfe_Item=
{
NULL,
-235,0,300,10,
HIGHCOMP|ITEMENABLED|ITEMTEXT|COMMSEQ,
0L,
&FTHilfe_Text,
NULL,
'H',NULL
};
struct Menu FTHilfe_Menu=
{
NULL,
560,0,70,10,
MENUENABLED,
"Hilfe",
&FTHilfe_Item
};
struct Menu Bearbeiten_Menu=
{
&FTHilfe_Menu,
140,0,130,10,
MENUENABLED,
"Bearbeiten",
&FU_Item
};
struct Menu Datei_Menu=
{
&Bearbeiten_Menu,
5,0,130,10,
MENUENABLED,
"Datei",
&FL_Item
};
#define MENU_DATEI 0
#define ITEM_LADEN 0
#define ITEM_SICHERN 1
#define ITEM_ENDE 3
#define MENU_BEARBEITEN 1
#define ITEM_UNDO 0
#define ITEM_KOMMENTAR 1
#define MENU_HILFE 2
#define ITEM_HILFE 0
UBYTE Kommentar[25];
UBYTE Undo[25];
struct StringInfo SInfo=
{
&Kommentar,
&Undo,
1,24
};
struct Gadget Kommentar_Gadget=
{
NULL,
230,51,198,10,
GADGHCOMP,
TOGGLESELECT|RELVERIFY,
STRGADGET,
NULL,NULL,NULL,
NULL,&SInfo,200,NULL
};
struct Gadget Aufnahme_Gadget=
{
NULL,
10,48,91,13,
GADGHCOMP,
TOGGLESELECT|GADGIMMEDIATE,
BOOLGADGET,
NULL,NULL,NULL,
NULL,NULL,102,NULL
};
struct Gadget *Shift_Gadget;
struct Gadget *Ctrl_Gadget;
UBYTE Nummer;
UBYTE Shift,Ctrl;
/* Codeposition ermitteln */
UBYTE *GetCode()
{
REGISTER UBYTE *code;
code=&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten.FTasten[Nummer-1];
if((Shift!=0)&&(Ctrl==0)) code=&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten.FTastenShift[Nummer-1];
if((Shift==0)&&(Ctrl!=0)) code=&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten.FTastenCtrl[Nummer-1];
if((Shift!=0)&&(Ctrl!=0)) code=&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten.FTastenShiftCtrl[Nummer-1];
return(code);
}
/* Kommentarposition ermitteln */
UBYTE *GetK()
{
REGISTER UBYTE *k;
k=&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten.FTastenKommentar[Nummer-1];
if((Shift!=0)&&(Ctrl==0)) k=&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten.FTastenShiftKommentar[Nummer-1];
if((Shift==0)&&(Ctrl!=0)) k=&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten.FTastenCtrlKommentar[Nummer-1];
if((Shift!=0)&&(Ctrl!=0)) k=&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten.FTastenShiftCtrlKommentar[Nummer-1];
return(k);
}
/* F-Tastenbelegungen zeigen */
VOID ZeigeFTasten()
{
UBYTE text[40];
UBYTE *code;
UBYTE *k;
REGISTER BOOL ende;
REGISTER ULONG Class;
REGISTER WORD i,Code;
struct Gadget *ZeigeShift_Gadget,*ZeigeCtrl_Gadget;
register struct Gadget *gad;
register struct Window *win;
register struct RastPort *rp;
register struct IntuiMessage *msg;
Shift=Ctrl=0;
win=CreateStdWindow("ATKeyboard - Funktionstastenbelegung zeigen",
75,75,460,164+BorderHeight(),
GADGETUP|GADGETDOWN|CLOSEWINDOW|VANILLAKEY,
WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE|ACTIVATE|GIMMEZEROZERO);
if(win!=NULL)
{
rp=win->RPort;
SetFont(rp,GetOpalFont());
ZeigeShift_Gadget=CreateNToggleGadget(win,10,2,120,12,"Shift",100);
ZeigeCtrl_Gadget=CreateNToggleGadget(win,135,2,120,12,"Control",101);
CreateBoolGadget(win,320,2,120,12,"Hilfe",102);
DrawNBorder(win,10,28,430,129);
ende=FALSE;
while(ende==FALSE)
{
for(Nummer=1;Nummer<=10;Nummer++)
{
i=Nummer*12;
SetAPen(rp,0);
RectFill(rp,19,20+i,439,30+i);
SelectStdFPen(rp);
sprintf(&text,"F%ld:",Nummer);
WriteText(rp,20,28+i,&text);
code=GetCode();
k=GetK();
if(code[0]==0)
{
strcpy(&text,"(Tastenkombination ist nicht belegt)");
}
else if((code[0]!=0)&&(k[0]==0))
{
strcpy(&text,"(Belegt, aber keine Benennung - Benutzen Sie \"Kommentar ändern\")");
}
else
{
strcpy(&text,k);
}
WriteText(rp,70,28+(Nummer*12),&text);
}
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
Class=msg->Class;
Code=msg->Code;
gad=msg->IAddress;
ReplyMsg(msg);
switch(Class)
{
case CLOSEWINDOW:
ende=TRUE;
break;
case GADGETUP:
case GADGETDOWN:
switch(gad->GadgetID)
{
case 100:
if(ZeigeShift_Gadget->Flags & SELECTED) Shift=1; else Shift=0;
break;
case 101:
if(ZeigeCtrl_Gadget->Flags & SELECTED) Ctrl=1; else Ctrl=0;
break;
case 102:
if(Class==GADGETUP) Help(HelpName,149);
break;
}
break;
case VANILLAKEY:
if(Code==13) ende=TRUE;
break;
}
}
DeleteStdWindow(win);
}
}
/* Tastencodes zeigen */
VOID ZeigeCode(rp,bool)
struct RastPort *rp;
{
REGISTER WORD x,y,n,anz;
UBYTE *code;
UBYTE tx[6];
if(bool==TRUE)
{
SetAPen(rp,0);
RectFill(rp,11,64,436,99);
}
SelectStdFPen(rp);
code=GetCode();
n=1; anz=code[0];
for(y=0;y<4;y++)
{
for(x=0;x<12;x++)
{
if(n<=anz)
{
sprintf(&tx,"$%02lx",code[n]);
WriteText(rp,18+(x*35),75+(y*12),&tx);
}
else
{
WriteText(rp,18+(x*35),75+(y*12)," ·");
}
n++;
}
}
}
VOID PrintK(win)
struct Window *win;
{
SetAPen(win->RPort,0);
RectFill(win->RPort,224,47,439,61);
DrawMNTextBorder(win,225,48,213,12,GetK());
}
/* Neue Belegung */
VOID Aufnahme(win)
struct Window *win;
{
UBYTE *code;
UBYTE *k;
REGISTER ULONG Class;
REGISTER UWORD Code;
REGISTER BOOL ende,ignore;
register struct IntuiMessage *msg;
register struct RastPort *rp;
register struct Gadget *gad;
REGISTER UBYTE n;
rp=win->RPort;
code=GetCode();
k=GetK();
strcpy(&Kommentar,k);
AddKGadget(win);
for(n=0;n<49;n++) code[n]=0x00;
ZeigeCode(rp,TRUE);
ende=FALSE;
ignore=FALSE;
n=1;
while(ende==FALSE)
{
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
Class=msg->Class;
Code=msg->Code;
gad=msg->IAddress;
ReplyMsg(msg);
switch(Class)
{
case RAWKEY:
if(n<=48)
{
if(!((ignore==TRUE)&&(Code==0xc4)))
{
code[n]=(UBYTE)Code;
code[0]=n;
n++;
ZeigeCode(rp,FALSE);
ignore=FALSE;
}
}
else
{
DisplayBeep(NULL);
}
break;
case GADGETUP:
if(gad->GadgetID==200) ignore=TRUE;
case GADGETDOWN:
if(gad->GadgetID==102) ende=TRUE;
break;
}
}
strcpy(k,&Kommentar);
RemoveGadget(win,&Kommentar_Gadget);
PrintK(win);
}
/* F-Tasten neu belegen */
VOID FTastenAendern()
{
REGISTER WORD i,w;
REGISTER ULONG Class;
REGISTER UWORD Code,id,MenuNum,ItemNum;
register struct Window *win;
register struct RastPort *rp;
register struct IntuiMessage *msg;
struct Gadget *IAddress;
BOOL ende,quit,changed;
UBYTE tx[30];
UBYTE fk[6];
UBYTE *k;
struct FTasten *FUndo;
struct FileHandler *fh;
ende=changed=FALSE;
Nummer=1;
Ctrl=0;
Shift=0;
FUndo=AllocMem(sizeof(struct FTasten),MEMF_CLEAR|MEMF_PUBLIC);
if(FUndo==NULL) return;
strcpy(&fk,"<F1>");
CopyMem(&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten,
FUndo,sizeof(struct FTasten));
Aufnahme_Gadget.Flags=GADGHCOMP;
win=CreateStdWindow("ATKeyboard - Funktionstasten belegen",
75,35,460,123+BorderHeight(),
GADGETDOWN|GADGETUP|CLOSEWINDOW|RAWKEY|MENUPICK,
WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE|ACTIVATE|GIMMEZEROZERO);
if(win!=NULL)
{
rp=win->RPort;
SetFont(rp,GetOpalFont());
AddGadget(win,&Aufnahme_Gadget,-1L);
OnGadget(&Aufnahme_Gadget,win,NULL);
CreateBoolGadget(win,10,5,210,12,"Einstellungen okay",1000);
CreateBoolGadget(win,227,5,210,12,"Einstellungen verwerfen",2000);
Shift_Gadget=CreateMinGadget(win,10,20,90,12,100);
Ctrl_Gadget=CreateMinGadget(win,10,34,90,12,101);
DrawPTextBorder(win,10,20,90,12,"Shift");
DrawPTextBorder(win,10,34,90,12,"Control");
DrawPTextBorder(win,10,48,90,12,"Aufnahme");
for(i=0;i<10;i++)
{
w=110+(i*33);
sprintf(&tx,"F%ld",i+1);
CreateBoolGadget(win,w,20,30,12,&tx,i+1);
}
DrawNBorder(win,10,63,428,55);
PrintK(win);
DrawCNTextBorder(win,110,34,328,12,"<Amiga>+<F1>");
WriteText(rp,125,58,"Kommentar:");
ZeigeCode(rp,TRUE);
SetMenuStrip(win,&Datei_Menu);
while(ende==FALSE)
{
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
Class=msg->Class;
Code=msg->Code;
IAddress=msg->IAddress;
ReplyMsg(msg);
switch(Class)
{
case CLOSEWINDOW:
if(changed==TRUE)
{
ende=UsePrefs();
if(ende==FALSE)
{
CopyMem(FUndo,
&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten,
sizeof(struct FTasten));
}
}
ende=TRUE;
break;
case MENUPICK:
MenuNum=MENUNUM(Code);
ItemNum=ITEMNUM(Code);
switch(MenuNum)
{
case MENU_DATEI:
switch(ItemNum)
{
case ITEM_LADEN:
if(FileRequester!=NULL)
{
k=FileReq("FKey-Datei laden:","#?.fkey");
}
else
{
k=StringAbfrage(FALSE,"FKey-Datei laden:","");
}
if((strcmp(k,"")))
{
fh=Open(k,MODE_OLDFILE);
if(fh!=NULL)
{
i=Read(fh,
&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten,
sizeof(struct FTasten));
if(i!=sizeof(struct FTasten))
{
Requester("FKey-Datei hat falsche","Länge/Falsches Format.","Okay",NULL);
CopyMem(FUndo,
&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten,
sizeof(struct FTasten));
}
else changed=TRUE;
Close(fh);
}
else
{
Requester("Die FKey-Datei konnte","nicht geöffnet werden.","Okay",NULL);
}
PrintK(win);
ZeigeCode(rp,TRUE);
}
break;
case ITEM_SICHERN:
if(FileRequester!=NULL)
{
k=FileReq("FKey-Datei sichern:","#?.fkey");
}
else
{
k=StringAbfrage(FALSE,"FKey-Datei sichern als:","");
}
if((strcmp(k,"")))
{
fh=Open(k,MODE_NEWFILE);
if(fh!=NULL)
{
Write(fh,
&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten,
sizeof(struct FTasten));
Close(fh);
}
else
{
Requester("Die FKey-Datei konnte","nicht erstellt werden.","Okay",NULL);
}
}
break;
case ITEM_ENDE:
ende=TRUE;
break;
}
break;
case MENU_BEARBEITEN:
switch(ItemNum)
{
case ITEM_UNDO:
CopyMem(FUndo,
&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten,
sizeof(struct FTasten));
PrintK(win);
ZeigeCode(rp,TRUE);
break;
case ITEM_KOMMENTAR:
k=GetK();
strcpy(&Kommentar,k);
AddKGadget(win);
ActivateGadget(&Kommentar_Gadget,win,NULL);
quit=FALSE; changed=TRUE;
while(quit==FALSE)
{
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
if(msg->Class==GADGETUP) quit=TRUE;
ReplyMsg(msg);
}
strcpy(k,&Kommentar);
RemoveGadget(win,&Kommentar_Gadget);
PrintK(win);
break;
}
break;
case MENU_HILFE:
if(ItemNum==ITEM_HILFE) Help(HelpName,148);
break;
}
break;
case GADGETDOWN:
id=IAddress->GadgetID;
if(id==102)
{
changed=TRUE;
Aufnahme(win);
}
break;
case GADGETUP:
id=IAddress->GadgetID;
if(id<1000)
{
if((id>=0)&&(id<=10))
{
Nummer=id;
sprintf(&fk,"<F%ld>",Nummer);
}
else if(id==100)
{
if(Shift==0)
{
Shift=1;
DrawNBorder(win,10,20,90,12);
}
else
{
Shift=0;
DrawPBorder(win,10,20,90,12);
}
}
else if(id==101)
{
if(Ctrl==0)
{
Ctrl=1;
DrawNBorder(win,10,34,90,12);
}
else
{
Ctrl=0;
DrawPBorder(win,10,34,90,12);
}
}
strcpy(&tx,"<Amiga>+");
if(Shift==1) strcat(&tx,"<Shift>+");
if(Ctrl==1) strcat(&tx,"<Control>+");
strcat(&tx,&fk);
PrintK(win);
DrawCNTextBorder(win,110,34,328,12,&tx);
ZeigeCode(rp,TRUE);
}
else
{
if(id==1000)
{
ende=TRUE;
}
else if(id==2000)
{
CopyMem(FUndo,
&KeyCodes->KeyTab[Einstellungen.Tastaturmodus].FTasten,
sizeof(struct FTasten));
ende=TRUE;
}
}
break;
}
}
ClearMenuStrip(win);
DeleteStdWindow(win);
}
FreeMem(FUndo,sizeof(struct FTasten));
}
VOID AddKGadget(win)
struct Window *win;
{
SetAPen(win->RPort,0);
RectFill(win->RPort,225,47,445,61);
AddGadget(win,&Kommentar_Gadget,-1L);
RefreshGadgets(&Kommentar_Gadget,win,NULL);
DrawNBorder(win,226,49,211,10);
DrawPBorder(win,225,48,213,12);
}